<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
<title>Messenger  Indicator</title>
<style type="text/css">
li {
    margin-bottom: 1px;
}
</style>
<script type="text/javascript">

var y = window.external;
var mess = y.Messenger;
var mainWindow = mess.MainWindow;
var conv_win = new Array();

function onLoad() {

    mess.SetEventHandler("WindowCreated", onWindowCreated);

    y.LocalReady();
}

function onWindowCreated (type, win) {
// Check if a new Conversation Window has been created
    if (type != "Conversation") return;
//    y.ToastShow("onWindowCreated", 5 , "Test");
    conv_win[conv_win.length - 1] = win;
// Check if the Calling Friend belongs to the Indicator group
    MyFriends = new Enumerator(win.Friends);
    MyFriend = MyFriends.item();
    FriendsGroups = new Enumerator(MyFriend.Groups);
    FriendsGroup  = FriendsGroups.item(); 
//    y.ToastShow("onWindowCreated", 5 , MyFriend.ID + "from Group " + FriendsGroup.Name);
    if ("Indicator" != FriendsGroup.Name) return;
// First Time we are called , so fire up the Device
    device_on();

// Event handlers
    win.SetEventHandler("Closed", on_WindowClosed);
    win.SetEventHandler("Activated", on_WindowActivated);
    win.SetEventHandler("UserIsTyping", on_UserIsTyping);
}

function device_on ()
{
    y.SendHTTPRequest(1, 'http://127.0.0.1:3490/ON');
    log_last_error('device_off');
}

function device_off ()
{
    y.SendHTTPRequest(1, 'http://127.0.0.1:3490/OFF');
    log_last_error('device_off');
}

function on_WindowClosed()
{
    device_off();
}

function on_WindowActivated(inFocus)
{
//    y.ToastShow("on_WindowActivated", 5 , inFocus);
    if (0!= inFocus) {
        device_off();
    } else {
        device_on();
    }
}

function on_IMReceived(msgrecv)
{
    y.ToastShow("on_IMReceived", 5 , "text");
}

function on_IncomingIM(msgrecv)
{
    y.ToastShow("on_IMReceived", 5 , "text");
}

function on_IMsent(msgrecv)
{
    y.ToastShow("on_IMReceived", 5 , "text");
}

function on_UserIsTyping()
{
    y.ToastShow("on_UserIsTyping", 5 , "text");
}

function log_last_error(name)
{
    if ("NoError" != y.LastError.ErrorID) {
        y.ToastShow("Error", 5 , name);
    }
}


</script>
</head>
<body onload="onLoad();">

<div id="container">
<ul>

<li>
Yahoo! IM Indicator Demo.
</li>

</ul></div>

</body>
</html>